package com.yiren.backstage.communication.analysis;


import com.yiren.backstage.currency.bean.GpsInfoBean;
import com.yiren.backstage.currency.enums.GpsStateEnum;
import com.yiren.backstage.currency.utils.GpsUtil;

/**
 * Time:2021/12/03 9:34
 * Author:xiaozan
 * Description:高精度 ksxt 数据解析
 */
public class KsxtDataAnalysis {

    private GpsInfoBean gpsInfo = GpsInfoBean.getInstance();


    public void dataAnalysis(String data){
        try {
            String[] arrayOfString = data.split(",");
            if (arrayOfString[0].equals("$KSXT") && arrayOfString.length >= 20) {
                gpsInfo.setUtcDateTime(arrayOfString[1]);
                GpsInfoBean gcj = GpsUtil.gps84_To_Gcj02(Double.parseDouble(arrayOfString[3]), Double.parseDouble(arrayOfString[2]));
                GpsInfoBean bd = GpsUtil.gcj02_To_Bd09(gcj.getLatitude(), gcj.getLongitude());
                gpsInfo.setLocation(bd.getLongitude(), bd.getLatitude());
                gpsInfo.setAltitude(Double.parseDouble(arrayOfString[4]));
                gpsInfo.setAnglePitch(Float.parseFloat(arrayOfString[6]));
                gpsInfo.setBearing(Float.parseFloat(arrayOfString[7]));
                gpsInfo.setSpeed(Float.parseFloat(arrayOfString[8]));

                gpsInfo.setStatusPosition(Integer.parseInt(arrayOfString[10]));

                gpsInfo.setStatusDirection(Integer.parseInt(arrayOfString[11]));
                if (!"".equals(arrayOfString[14])) {
                    float distanceX = Float.parseFloat(arrayOfString[14]);
                    gpsInfo.setDistanceX(distanceX);
                }
                if (!"".equals(arrayOfString[15])) {
                    float distanceY = Float.parseFloat(arrayOfString[15]);
                    gpsInfo.setDistanceY(distanceY);
                }
                if (!"".equals(arrayOfString[16])) {
                    gpsInfo.setDistanceZ(Float.parseFloat(arrayOfString[16]));
                }
                gpsInfo.setAzimuth(Float.parseFloat(arrayOfString[5]));
                if (Integer.parseInt(arrayOfString[10]) == 0) {
                    gpsInfo.setExternalLocationState(GpsStateEnum.LOCATIONING);
                } else {
                    gpsInfo.setExternalLocationState(GpsStateEnum.LOCATION_SUCCESS);
                }
                gpsInfo.setSatelliteFront(Integer.parseInt(arrayOfString[12]));
                gpsInfo.setSatelliteBack(Integer.parseInt(arrayOfString[13]));

                if (!"".equals(arrayOfString[17])) {
                    gpsInfo.setVelocityX(Float.parseFloat(arrayOfString[17]));
                    gpsInfo.setVelocityY(Float.parseFloat(arrayOfString[18]));
                    gpsInfo.setVelocityZ(Float.parseFloat(arrayOfString[19]));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
